<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>CustomButton</title>
</head>

<body>
    <div id="app">
        <h1>Chapter 2</h1> 
        <positive-numbers></positive-numbers> 
    </div>
    <script>
      Vue.component('positive-numbers',{
        template:'<p>有{{positiveNumbers.length}}个正数</p>',
        data(){
          return {
            numbers:[-5,0,2,-1,1,0.5]
          };
        },
        computed:{
          positiveNumbers(){
            return this.numbers.filter((n)=>n>=0);
          }
        }
      });
       
        new Vue({
            el: '#app' 
        });

    </script>
</body>

</html>
